define(function (require, exports, module) {
    'use strict';
    
    var rk = require('rk');

var animateDuration = 300;

$.widget('rk.waveGuiderCtrl', {
        _create: function(){
            var me = this;
            var elem = me.element;
            rk.oa.closePanel();
            rk.oa.closeContent();
            window.setTimeout(function(){
                me.initWaves();
            }, 200);
        },
        initWaves: function(){
            var me = this;

            $('#wave_foldbtn').off().remove();
            $('#wave_unfoldbtn').off().remove();
            $('#wave_oamenu').off().remove();
            $('#wave_oafoldbtn').off().remove();

            //foldbtn, unfoldbtn, oamenu, oafoldbtn
            $(document.body).append('<img id="wave_foldbtn" style="position:fixed;left:170px;top:2px;cursor: pointer; z-index:200; display:none;" src="/static/img/svg-loaders/puff.svg" width="50" alt="">');
            $(document.body).append('<img id="wave_unfoldbtn" style="position:fixed;left:3px;top:2px;cursor: pointer; z-index:200; display:none;" src="/static/img/svg-loaders/puff.svg" width="50" alt="">');
            $(document.body).append('<img id="wave_oamenu" style="position:fixed;right:8px;top:5px;cursor: pointer; z-index:200; " src="/static/img/svg-loaders/puff-dark.svg" width="50" alt="">');
            $(document.body).append('<img id="wave_oafoldbtn" style="position:fixed;right:6px;top:5px;cursor: pointer; z-index:200; display:none;" src="/static/img/svg-loaders/puff-dark.svg" width="50" alt="">');
            $(document.body).append('<img id="wave_privatemsg" style="position:fixed;right:8px;bottom:-16px;cursor: pointer; z-index:200;" src="/static/img/svg-loaders/puff-dark.svg" width="50" alt="">');
            
            $('#wave_privatemsg').css('bottom', $('#privatemsg').css('bottom'));

            var leftIsFolding = $('#pageleft').pageLeftCtrl('isFolding');
            var firstBtnId, secondBtnId;
            if(!leftIsFolding){
                firstBtnId = '#wave_foldbtn';
                secondBtnId = '#wave_unfoldbtn';
            }else{
                firstBtnId = '#wave_unfoldbtn';
                secondBtnId = '#wave_foldbtn';
            }

            $(firstBtnId).show();

            if(!leftIsFolding){
                $(firstBtnId).click(function(){
                    var btn = $(this);
                    $('#pageleft').pageLeftCtrl('option', 'onSysFold', function(){                
                        window.setTimeout(function(){
                            $(secondBtnId).show();
                            $('#pageleft').pageLeftCtrl('option', 'onSysFold', function(){});
                        }, 200);
                    });
                    $('#pageleft').pageLeftCtrl('fold');
                    btn.off().remove();
                });
                $('#wave_unfoldbtn').click(function(){
                    var btn = $(this);
                    $('#pageleft').pageLeftCtrl('unfold');
                    btn.off().remove();
                });
            }else{
                $(firstBtnId).click(function(){
                    var btn = $(this);
                    $('#pageleft').pageLeftCtrl('option', 'onSysUnFold', function(){                
                        window.setTimeout(function(){
                            $(secondBtnId).show();
                            $('#pageleft').pageLeftCtrl('option', 'onSysUnFold', function(){});
                        }, 200);
                    });
                    $('#pageleft').pageLeftCtrl('unfold');
                    btn.off().remove();
                });
                $('#wave_foldbtn').click(function(){
                    var btn = $(this);
                    $('#pageleft').pageLeftCtrl('fold');
                    btn.off().remove();
                });
            }

            $('#wave_oamenu').click(function(){
                var btn = $(this);
                $('#oamenubar').pageOAMenuCtrl('option', 'onSysPanelOpen', function(){
                    $('#oamenubar').pageOAMenuCtrl('option', 'onSysPanelOpen', function(){});
                    window.setTimeout(function(){
                        $('#wave_oafoldbtn').show();
                    }, 300);
                });
                window.setTimeout(function(){
                    $('#oamenubar').pageOAMenuCtrl('openMenu');
                }, 20);                
                btn.off().remove();
            });
            $('#wave_oafoldbtn').click(function(){
                var btn = $(this);
                rk.oa.hidePanel();
                btn.off().remove();
            });
            $('#wave_privatemsg').click(function(){
                var btn = $(this);
                $('.pg-pm-thumb').click();
                btn.off().remove();
            });
        },
        initStep0: function(){
            var me = this;

        },
        _clean: function(){
            var me = this;

        },
        report: function(){
                    $.ajax({
                        url: '/json/crm_schedule/finish-guide.action',
                        data:{},
                        dataType: 'json'
                    })
                    .success(function( data ){})
                    .error(function(){})
                    .done(function(){});
        }
});
});